package com.lanou.zakerproject.disport;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

import com.lanou.zakerproject.R;
import com.lanou.zakerproject.base.BaseActivity;


/**
 * Created by dllo on 16/1/20.
 */
public class DisportDetailActivity extends BaseActivity {
    private Toolbar toolbar;
    private TextView textView;
    private WebView webView;
    private String  detail_title,disport_detail_url;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_disport_detail);
        toolbar = (Toolbar) findViewById(R.id.disport_detail_toobar);
        textView = (TextView) findViewById(R.id.disport_detail_tv);
        webView = (WebView) findViewById(R.id.disport_detail_webView);
        setSupportActionBar(toolbar);
        toolbar.setTitle("");
        toolbar.setOnMenuItemClickListener(onMenuItemClick);
        Intent intent = getIntent();
        detail_title = intent.getStringExtra("disport_detail_title");
        disport_detail_url =intent.getStringExtra("disport_detail_url");
        textView.setText(detail_title);
        webView.getSettings().setJavaScriptEnabled(true);
        //加载需要显示的网页
        webView.loadUrl(disport_detail_url);
        //设置Web视图
//        setContentView(webview);
        webView.setWebViewClient(new WebViewClient() {
            //  重写此方法表明点击网页里面的链接还是在当前的webview里跳转，不跳到浏览器那边
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_disport_detail, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        return super.onOptionsItemSelected(item);
    }

    private Toolbar.OnMenuItemClickListener onMenuItemClick = new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            switch (menuItem.getItemId()) {
                case R.id.web_out:
                    toast("使用浏览器打开");
                    break;
                case R.id.share:
                    toast("分享");
                    break;
                case R.id.address_cppy:
                    toast("复制地址");
                    break;

            }
            return true;
        }
    };
}
